

/*
William D. Hicks (hickswd@appstate.edu), Carl E. Klarner (Carl.Klarner@gmail.com),  
   Seth C. McKee (sc.mckee@ttu.edu), and Daniel A. Smith (dasmith@ufl.edu)  
   "Revisiting Majority-Minority Districts and Black Representation" in PRQ
*/

/*
Authorship of the data posted here: Carl E. Klarner.  
Authorship of the do-files posted here: William D. Hicks and Carl E. Klarner.  

It reproduces Figures 1 through 3 in the article  

See REPLICATION_CODE_LEGISLATORS.do for other tables and figures
	
Last update to this file: 06/01/2018
Second to last update update to this file: 09/26/2017 

This file directs the following tasks:
   (1) set directory *critical for using datasets with variable labels
   (2) load datasets, label variables, and save files to DIRECTORY  
      -REPLICATION_DATA_LEGISLATURES_FILE1.dta
	  -REPLICATION_DATA_LEGISLATURES_FILE2.dta
	  -REPLICATION_DATA_LEGISLATURES_FILE3.dta
   (3) reproduce FIGURES 1a-1b in a single .pdf file 
      - FIGURE_1.pdf	 
   (4) reproduce FIGURES 2a-2b in a single .pdf file 
      - FIGURE_2.pdf   
   (5) reproduce FIGURES 3a-3b in a .pdf file 
      - FIGURE_3.pdf 
*/


/*

			THE ENTIRE DO-FILE NEEDS TO BE RUN IN ONE RUN FOR IT TO EXECUTE PROPERLY.  

            PUT THE DIRECTORY PATH OF THE FOLDER WHERE THE FILES TO BE IMPORTED ARE STORED
*/
local outputdirectory "cd C:\Users\User\Dropbox\02_Overfile20180516\08Elections\Project_DescRepPaper\ReplicationDataset3MyVersionOfficial\Output"

/*
            PUT THE DIRECTORY PATH OF THE FOLDER WHERE THE FILES TO BE EXPORTED ARE STORED
*/
local inputdirectory "cd C:\Users\User\Dropbox\02_Overfile20180516\08Elections\Project_DescRepPaper\ReplicationDataset3MyVersionOfficial\Input"


/*                           
                    VARIABLE DEFINITIONS AND LABELS FILE 1
*/
clear
`inputdirectory'
use REPLICATION_DATA_LEGISLATURES_FILE1.dta

label var sessyear "Year of Legislative Session" 
label var dem "Percentage of Lawmakers who are Democrats" 
label var repub "Percentage of Lawmakers who are Republicans"  
label var blackdem "Percentage of Lawmakers who are Black and Democrats"  
label var blackrepub "Percentage of Lawmakers who are Black and Republicans"  
label var dem_w "Percentage of Lawmakers who are Democrats (weighted by population)"  
label var repub_w "Percentage of Lawmakers who are Republicans (weighted by population)"  
label var blackdem_w "Percentage of Lawmakers who are Black and Democrats (weighted by population)"  
label var blackrepub_w "Percentage of Lawmakers who are Black and Republicans (weighted by population)"

`outputdirectory'
save REPLICATION_DATA_LEGISLATURES_FILE1b.dta, replace  
*save this dataset to run commands below 

/*                           
                    VARIABLE DEFINITIONS AND LABELS FILE 2
*/
`inputdirectory'
use REPLICATION_DATA_LEGISLATURES_FILE2.dta, clear 

label var sessyear "Year of Legislative Session" 
label var south "South Indicator (1=yes; 0=no)"
label var dem "Percentage of Lawmakers who are Democrats" 
label var repub "Percentage of Lawmakers who are Republicans"  
label var blackdem "Percentage of Lawmakers who are Black and Democrats"  
label var blackrepub "Percentage of Lawmakers who are Black and Republicans"  
label var dem_w "Percentage of Lawmakers who are Democrats (weighted by population)"  
label var repub_w "Percentage of Lawmakers who are Republicans (weighted by population)"  
label var blackdem_w "Percentage of Lawmakers who are Black and Democrats (weighted by population)"  
label var blackrepub_w "Percentage of Lawmakers who are Black and Republicans (weighted by population)"

`outputdirectory'
save REPLICATION_DATA_LEGISLATURES_FILE2b.dta, replace  
*save this dataset to run commands below 


/*                           
                    VARIABLE DEFINITIONS AND LABELS FILE 3
*/

`inputdirectory'
use REPLICATION_DATA_LEGISLATURES_FILE3.dta, clear 


label var sessyear "Year of Legislative Session" 
label var southdetail "Non-South / Deep South / Rim South"
label var dem "Percentage of Lawmakers who are Democrats" 
label var repub "Percentage of Lawmakers who are Republicans"  
label var blackdem "Percentage of Lawmakers who are Black and Democrats"  
label var blackrepub "Percentage of Lawmakers who are Black and Republicans"  
label var dem_w "Percentage of Lawmakers who are Democrats (weighted by population)"  
label var repub_w "Percentage of Lawmakers who are Republicans (weighted by population)"  
label var blackdem_w "Percentage of Lawmakers who are Black and Democrats (weighted by population)"  
label var blackrepub_w "Percentage of Lawmakers who are Black and Republicans (weighted by population)"


`outputdirectory'
save REPLICATION_DATA_LEGISLATURES_FILE3b.dta, replace  
*save this dataset to run commands below 



/*************   Figures 1a-1b: PARTISAN SPLIT SOUTH V NON-SOUTH ***************/


use REPLICATION_DATA_LEGISLATURES_FILE2b.dta, clear

keep if south==0
twoway ///
(lowess  dem_w sessyear, lcolor(gs3) lpattern(shortdash_dot) lwidth(thick) xlabel(1972(4)2016, angle(45)) ylabel(0(10)100, nogrid) xtitle("") xtitle("") xsize(1) ysize(1.2) ) ///
(scatter dem_w sessyear, mcolor(gs3) msymbol(o) msize(large)) ///
(lowess repub_w sessyear, lcolor(gs9) lwidth(thick) lpattern(longdash_dot) msize(large)) ///
(scatter repub_w sessyear, mcolor(gs9) msymbol(oh) msize(large)) ///
, scheme(s2mono) graphregion(fcolor(white) icolor(white) lcolor(white)) ///
legend(label (1 "Dem Trend") label (2 "Dem %") label (3 "Rep Trend") label (4 "Rep %") ) ///
ytitle("") saving(FIGURE_1a, replace)

use REPLICATION_DATA_LEGISLATURES_FILE2b.dta, clear

keep if south==1
twoway ///
(lowess  dem_w sessyear, lcolor(gs3) lpattern(shortdash_dot) lwidth(thick) xlabel(1972(4)2016, angle(45)) ylabel(0(10)100, nogrid) xtitle("") xtitle("") xsize(1) ysize(1.2) ) ///
(scatter dem_w sessyear, mcolor(gs3) msymbol(o) msize(large)) ///
(lowess repub_w sessyear, lcolor(gs9) lpattern(longdash_dot) lwidth(thick) msize(large)) ///
(scatter repub_w sessyear, mcolor(gs9) msymbol(oh) msize(large)) ///
, scheme(s2mono) graphregion(fcolor(white) icolor(white) lcolor(white)) ///
legend(label (1 "Dem Trend") label (2 "Dem %") label (3 "Rep Trend") label (4 "Rep %") ) ///
ytitle("") saving(FIGURE_1b, replace)

gr combine FIGURE_1a.gph FIGURE_1b.gph, col(2) scheme(s1mono) xcommon
graph export FIGURE_1.pdf, replace


/*************** Figures 2a-2b: BLACK DEMOCRATS AMONG REGIONS *****************/



*Figure 2a percent black Dem legislators in Non-South/South/Nation from 1971 to 2015 (weighted loess)

use REPLICATION_DATA_LEGISLATURES_FILE1b.dta, clear
keep blackdem_w blackrepub_w sessyear
rename blackdem_w blackdemnat_w
rename blackrepub_w blackrepubnat_w
save temp.dta, replace
use REPLICATION_DATA_LEGISLATURES_FILE2b.dta, clear
keep if south==0
keep blackdem_w blackrepub_w sessyear
rename blackdem_w blackdemnonsouth_w
rename blackrepub_w blackrepubnonsouth_w
merge 1:1 sessyear using temp.dta
drop _merge
save temp.dta, replace
use REPLICATION_DATA_LEGISLATURES_FILE2b.dta, clear
keep if south==1
keep blackdem_w blackrepub_w sessyear
rename blackdem_w blackdemsouth_w
rename blackrepub_w blackrepubsouth_w
merge 1:1 sessyear using temp.dta
drop _merge
save temp.dta, replace



twoway ///
(lowess  blackdemnat_w sessyear, lcolor(gs2) lp(solid) lwidth(thick) xlabel(1972(4)2016, angle(45)) ylabel(0(5)25, nogrid) xtitle("") xtitle("") xsize(1) ysize(1.2) ) ///
(scatter blackdemnat_w sessyear, mcolor(gs2) msymbol(o) msize(large)) ///
(lowess blackdemnonsouth_w sessyear, lcolor(gs4) lwidth(thick) msize(large)) ///
(scatter blackdemnonsouth_w sessyear, mcolor(gs4) msymbol(dh) msize(large)) ///
(lowess blackdemsouth_w sessyear, lcolor(gs6) lp(shortdash_dot) lwidth(thick) msize(large)) ///
(scatter blackdemsouth_w sessyear, mcolor(gs6) msymbol(sh) msize(large)) ///
, scheme(s2mono) graphregion(fcolor(white) icolor(white) lcolor(white)) ///
legend(label (1 "Nat Trend") label (2 "Nat %") label (3 "Non-South Trend") label (4 "Non-South %") label (5 "South Trend") label (6 "South %") ) ///
ytitle("") saving(FIGURE_2a, replace)




*Figure 2b percent black Dem legislators in Rim South/Deep South/South from 1971 to 2015 (weighted loess)
use REPLICATION_DATA_LEGISLATURES_FILE2b.dta, clear
keep if south==1
keep blackdem_w blackrepub_w sessyear
rename blackdem_w blackdemsouth_w
rename blackrepub_w blackrepubsouth_w
save temp.dta, replace
use REPLICATION_DATA_LEGISLATURES_FILE3b.dta, clear
keep if southdetail=="rimsouth"
keep blackdem_w blackrepub_w sessyear
rename blackdem_w blackdemrim_w
rename blackrepub_w blackrepubrim_w
merge 1:1 sessyear using temp.dta
drop _merge
save temp.dta, replace
use REPLICATION_DATA_LEGISLATURES_FILE3b.dta, clear
keep if southdetail=="deepsouth"
keep blackdem_w blackrepub_w sessyear
rename blackdem_w blackdemdeep_w
rename blackrepub_w blackrepubdeep_w
merge 1:1 sessyear using temp.dta 
drop _merge
save temp.dta, replace

*following makes the figure

twoway ///
(lowess  blackdemsouth_w sessyear, lcolor(gs6) lp(shortdash_dot) lwidth(thick) xlabel(1972(4)2016, angle(45)) ylabel(0(5)25, nogrid) xtitle("") xtitle("") xsize(1) ysize(1.2) ) ///
(scatter blackdemsouth_w sessyear, mcolor(gs6) msymbol(sh) msize(large)) ///
(lowess blackdemdeep_w sessyear, lcolor(gs8) lwidth(thick) msize(large)) ///
(scatter blackdemdeep_w sessyear, mcolor(gs8) msymbol(oh) msize(large)) ///
(lowess blackdemrim_w sessyear, lcolor(gs10) lwidth(thick) msize(large)) ///
(scatter blackdemrim_w sessyear, mcolor(gs10) msymbol(th) msize(large)) ///
, scheme(s2mono) graphregion(fcolor(white) icolor(white) lcolor(white)) ///
legend(label (1 "South Trend") label (2 "South %") label (3 "Deep South Trend") label (4 "Deep South %") label (5 "Rim South Trend") label (6 "Rim South %") ) ///
ytitle("") saving(FIGURE_2b, replace)


gr combine FIGURE_2a.gph FIGURE_2b.gph, col(2) scheme(s1mono) xcommon
graph export FIGURE_2.pdf, replace




/************************* Figures 3a-3b **************************/


*Figure 3a partisan split in Rim South by year from 1971 to 2015 (weighted loess)

use REPLICATION_DATA_LEGISLATURES_FILE3b.dta, clear
keep if southdetail=="rimsouth"
twoway ///
(lowess  dem_w sessyear, lcolor(gs3) lp(shortdash_dot) lwidth(thick) xlabel(1972(4)2016, angle(45)) ylabel(0(10)100, nogrid) xtitle("") xtitle("") xsize(1) ysize(1.2) ) ///
(scatter dem_w sessyear, mcolor(gs3) msymbol(o) msize(large)) ///
(lowess repub_w sessyear, lcolor(gs9) lp(longdash_dot) lwidth(thick) msize(large)) ///
(scatter repub_w sessyear, mcolor(gs9) msymbol(oh) msize(large)) ///
, scheme(s2mono) graphregion(fcolor(white) icolor(white) lcolor(white))  ///
legend(label (1 "Dem Trend") label (2 "Dem %") label (3 "Rep Trend") label (4 "Rep %") ) ///
ytitle("") saving(FIGURE_3a, replace) 



*Figure 3b partisan split in Deep South by year from 1971 to 2015 (weighted loess)
use REPLICATION_DATA_LEGISLATURES_FILE3b.dta, clear
keep if southdetail=="deepsouth"
twoway ///
(lowess  dem_w sessyear, lcolor(gs3) lp(shortdash_dot) lwidth(thick) xlabel(1972(4)2016, angle(45)) ylabel(0(10)100, nogrid) xtitle("") xtitle("") xsize(1) ysize(1.2) ) ///
(scatter dem_w sessyear, mcolor(gs3) msymbol(o) msize(large)) ///
(lowess repub_w sessyear, lcolor(gs9) lp(longdash_dot) lwidth(thick) msize(large)) ///
(scatter repub_w sessyear, mcolor(gs9) msymbol(oh) msize(large)) ///
, scheme(s2mono) graphregion(fcolor(white) icolor(white) lcolor(white))  ///
legend(label (1 "Dem Trend") label (2 "Dem %") label (3 "Rep Trend") label (4 "Rep %") ) ///
ytitle("") saving(FIGURE_3b, replace) 



gr combine FIGURE_3a.gph FIGURE_3b.gph, col(2) scheme(s1mono) xcommon
graph export  FIGURE_3.pdf, replace


